package Reflect;

import java.lang.reflect.Method;

@Pro(ClassName = "Reflect.Person", methodName = "eat")
public class Reflect_homework2 {
    public static void main(String[] args) throws Exception {
        Class<Reflect_homework2> reflect_homework2Class = Reflect_homework2.class;
        //获取上面的字节码文件
        Pro annotion = reflect_homework2Class.getAnnotation(Pro.class);
        //在内存中生成了一个注释接口的子类实现对象 上面这行
        //调用注解中的抽象方法获取返回值
        String s = annotion.ClassName();
        String m = annotion.methodName();

        //加载该类进内存
        Class cls = Class.forName(s);
        //创建对象
        Object obj = cls.newInstance();
        //获取方法对象
        Method method = cls.getMethod(m);

        //执行方法
        method.invoke(obj);
    }
}
